//
//  SettingView.swift
//  Share
//
//  Created by admin on 2020/10/9.
//  Copyright © 2020 MBA. All rights reserved.
//

import SwiftUI

var baseurl:String = UserDefaults.standard.string(forKey: "baseurl") ?? "http://10.10.11.171:1337"


struct SettingView: View {
    
    @State var _baseurl:String = baseurl
    @State var _isSql:Bool = UserDefaults.standard.bool(forKey: "isSql")
  
    
    func save() {
        UserDefaults.standard.set(_baseurl, forKey: "baseurl")
        baseurl = UserDefaults.standard.string(forKey: "baseurl")!
        UserDefaults.standard.set(_isSql, forKey: "isSql")

    }
    
    
    var body: some View {
        NavigationView{
            Form{
             
                Section {
                    HStack{
                        Text("服务器地址")
                        TextField("服务器地址", text: $_baseurl)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .foregroundColor(Color("lable1"))
                    }
                    Toggle("是否使用本地数据", isOn: $_isSql)
                }
          
         
                
                
            }
            .background(Color("background2"))
            .navigationTitle("设置")
            .navigationBarItems(
                trailing: Button(action: save) { Image(systemName: "square.and.arrow.down")
                    .frame(width: 32, height: 32, alignment: .center) }
            )
            
        }
    }
}

struct SettingView_Previews: PreviewProvider {
    static var previews: some View {
        SettingView()
            .preferredColorScheme(.dark)
    }
}
